package cn.xiaozhi0802.test;

import cn.xiaozhi0802.dao.IAccountDao;
import cn.xiaozhi0802.domain.Account;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.InputStream;
import java.util.List;

public class MyBatis {
    @Test
    public void run1() throws Exception {
        //加载配置文件
        InputStream in = Resources.getResourceAsStream("SqlMapConfig.xml");
        //创建SqlSessionFactory对象
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(in);
        //创建SqlSession对象
        SqlSession session = factory.openSession();
        //获取到代理对象
        IAccountDao dao = session.getMapper(IAccountDao.class);
        //查询所有数据
        List<Account> all = dao.findAll();
        for (Account account : all) {
            System.out.println(account);
        }
        session.close();
        in.close();

    }
}
